cmake_minimum_required(VERSION 3.10)
project(flashlight-examples)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# If building in source, we already have these targets.
if (NOT TARGET flashlight)
  find_package(flashlight)
endif ()
if (NOT TARGET ArrayFire)
  find_package(ArrayFire)
endif ()

function(build_example SRCFILE)
  get_filename_component(src_name ${SRCFILE} NAME_WE)
  set(target "${src_name}")
  add_executable(${target} ${SRCFILE})
  if (TARGET flashlight)
    target_link_libraries(${target} PRIVATE flashlight)
  else ()
    target_link_libraries(${target} PRIVATE flashlight::flashlight)
  endif()
endfunction(build_example)

build_example(Benchmark.cpp)
build_example(Mnist.cpp)
build_example(RnnLm.cpp)
build_example(RnnClassification.cpp)
build_example(LinearRegression.cpp)
build_example(Perceptron.cpp)
build_example(Classification.cpp)
build_example(Xor.cpp)
build_example(AdaptiveClassification.cpp)

if (FL_BUILD_DISTRIBUTED OR TARGET flashlight::Distributed)
  build_example(DistributedTraining.cpp)
endif ()
